﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace _201206QuanLyBanHang.ThuVien
{
    class Class_Database
    {
        DataConn da;

        public Class_Database()
        {
            da = new DataConn();
        }
        public DataSet getDMKhachHang(string strsql)
        {
            return da.ExectueQueryDataset(strsql, CommandType.Text, null);
        }
        //Đưa dữ liệu vào combobox
        public void fillCombo(string sql, ComboBox cmb, string text, string value)
        {
            DataSet ds = new DataSet();
            ds = da.ExectueQueryDataset(sql, CommandType.Text, null);
            cmb.DataSource = ds.Tables[0];
            cmb.DisplayMember = text;
            cmb.ValueMember = value;
        }
        // Lấy danh sách từ sql sever ra dataset
        public DataSet ds_dataset(string strsql)
        {
            return da.ExectueQueryDataset(strsql, CommandType.Text, null);
        }
            //
            public DataTable getDatatable(String sql)
        {
            //String sql = "select convert(varchar, NgayThanhToan, 103) as NgayThanhToan, replace(convert(varchar, cast(SoTienThanhToan as money), 1),'.00','') as SoTienThanhToan, GhiChuKHTT from KhachHang_ThanhToan where MaKH='" + MaKH + "' order by NgayThanhToan desc";
            return da.GetDataTable(sql);
        }
            
        
        private void LoadDataToCollection()
        {
            AutoCompleteStringCollection auto2 = new AutoCompleteStringCollection();

            string sql = "Select dbo.fnChuyenKhongDau(tencuahang) as tencuahang  from khachhang ";
          
            SqlDataReader reader;
           
            reader = da.ThucHienReader(sql);
            if (reader != null)
            {
                while (reader.Read())
                {
                    auto2.Add(reader["tencuahang"].ToString());
                }
            }

           


        }
    }
}
